#coding=utf-8
'''
Created on 2017-06-7

@author: zhangyadong
'''

import logging


class Config(object):
    def __init__(self):
        self.card = 0
        self.min = 0
        self.max = 0
        self.back = 0

    def parse(self,js):
        self.card = js.get("card")
        self.min = js.get("min")
        self.max = js.get("max")
        self.back = js.get("back")
        logging.debug(u"test pudate file max = %d",self.max)

class GiveBackCardConfig(object):
    
    def __init__(self):
        self.__map = {}
        
    def onRemoteConfig(self, cfgname, jf):
        if cfgname!= u"loginconfig.givebackcard":
            #logging.info("cfgname = %s",cfgname); 
            return
        self.loadFromJson(jf)
            
    def loadFromJson(self, jf):
        for i in range(len(jf)):
            js = jf[i]
            cf = Config()
            cf.parse(js)
            if self.__map.get(cf.card,None) == None:
                self.__map[cf.card] = []
            self.__map[cf.card].append(cf)
            
        
    def getGiveBackCardNum(self,card,curRound):
        reCard = 0
        configs = self.__map.get(card)
        for i in range(len(configs)):
            cf = configs[i]
            if curRound >= cf.min and curRound <= cf.max:
                reCard = cf.back
                break
        return reCard
    
instance = GiveBackCardConfig()

if __name__ == '__main__':
    pass